<?php
/**
 * https://gitee.com/litephp
 * http://www.dazhetu.cn/
 * jay_fun 410136330@qq.com
 * Date: 2019/1/11
 * Time: 15:33
 */

namespace app\admin\controller\content;

use app\common\controller\BaseAdmin;
use app\common\model\content\Banner as BannerModel;
use LiteAdmin\Music163;
use think\db;

/**
 * @title 首页轮播图
 * Class Music
 * @package app\admin\controller\content
 */
class Banner extends BaseAdmin
{
    /**
     * @title 首页轮播图
     * @return mixed
     */
    public function index()
    {
        $db = BannerModel::alias('r')

            ->field('r.*')
            ->order('create_time desc');

        $search = $this->request->get();
        // 精准查询
        foreach (['status'] as $field){
            if (isset($search[$field]) && $search[$field] !== ''){
                $db->where('r.'.$field,'=', $search[$field]);
            }
        }
        // 模糊查询
        foreach (['uname'] as $field){
            if (isset($search[$field]) && $search[$field] !== ''){
                $db->whereLike('u.'.$field, "%{$search[$field]}%");
            }
        }
        return $this->_list($db, true, $search);
    }

    /**
     * @title 添加轮播图
     * @return array|mixed
     */
    public function add()
    {
        return $this->_form(new BannerModel(), 'form');
    }
    /**
     * @title 删除轮播图
     */
    public function del()
    {
        $ids = $this->request->post('ids',false);
        !$ids && $this->error("缺少参数！");

        $this->_del(new BannerModel(),$ids);
    }

    /**
     * @title 编辑操作
     * @return array|mixed
     */
    public function edit()
    {
        return $this->_form(new BannerModel(), 'form');
    }

}